package com.example.zqm.git72.Fragment;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.example.zqm.git72.Adapter.ActivityListAdapter;
import com.example.zqm.git72.Adapter.ClubListAdapter;
import com.example.zqm.git72.Adapter.MasterListAdapter;
import com.example.zqm.git72.JavaBean.Activity;
import com.example.zqm.git72.JavaBean.Master;
import com.example.zqm.git72.Model.ActivityModel;
import com.example.zqm.git72.Model.MasterModel;
import com.example.zqm.git72.R;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class MasterFragment extends BaseFragment {
    public List<Master> masters;
    private RecyclerView recyclerView;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View v = inflater.inflate( R.layout.fragment_container, container, false);
        recyclerView = (RecyclerView)v.findViewById(R.id.home_home);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
        return v;
    }
    @Override
    public void onResume() {
        super.onResume();
        initData();
    }

    public void initData(){
        MasterModel masterModel = new MasterModel();

        Call<List<Master>> call = masterModel.getList();
        call.enqueue(new Callback<List<Master>>() {
            @Override
            public void onResponse(Call<List<Master>> call, Response<List<Master>> response) {
                masters = response.body();
                recyclerView.setAdapter(new MasterListAdapter(getActivity(), masters));//设置适配器

            }

            @Override
            public void onFailure(Call<List<Master>> call, Throwable t) {

            }
        });

    }

}
